﻿@model NeverSoldReportModel
@inject AdminAreaSettings adminAreaSettings

@{
    var defaultGridPageSize = adminAreaSettings.DefaultGridPageSize;
    var gridPageSizes = adminAreaSettings.GridPageSizes;

    //page title
    ViewBag.Title = T("Admin.SalesReport.NeverSold").Text;
    //active menu item (system name)
    Html.SetActiveMenuItemSystemName("Products never purchased");
}

<nop-antiforgery-token />
<div class="content-header clearfix">
    <h1 class="pull-left">
        @T("Admin.SalesReport.NeverSold")
    </h1>
    <div class="pull-right">
        &nbsp;
    </div>
</div>

<div class="content">
    <div class="form-horizontal">
        <div class="panel-group">
            <div class="panel panel-default">
                <div class="panel-body">
                    <div class="row">
                        <div class="col-md-5">
                            <div class="form-group" @(Model.AvailableCategories.SelectionIsNotPossible() ? Html.Raw("style=\"display:none\"") : null)>
                                <div class="col-md-4">
                                    <nop-label asp-for="SearchCategoryId" />
                                </div>
                                <div class="col-md-8">
                                    <nop-select asp-for="SearchCategoryId" asp-items="Model.AvailableCategories" />
                                </div>
                            </div>
                            <div class="form-group" @(Model.AvailableManufacturers.SelectionIsNotPossible() ? Html.Raw("style=\"display:none\"") : null)>
                                <div class="col-md-4">
                                    <nop-label asp-for="SearchManufacturerId" />
                                </div>
                                <div class="col-md-8">
                                    <nop-select asp-for="SearchManufacturerId" asp-items="Model.AvailableManufacturers" />
                                </div>
                            </div>
                            <div class="form-group" @(Model.AvailableStores.SelectionIsNotPossible() ? Html.Raw("style=\"display:none\"") : null)>
                                <div class="col-md-4">
                                    <nop-label asp-for="SearchStoreId" />
                                </div>
                                <div class="col-md-8">
                                    <nop-select asp-for="SearchStoreId" asp-items="Model.AvailableStores" />
                                </div>
                            </div>
                            <div class="form-group" @(Model.AvailableVendors.SelectionIsNotPossible() || Model.IsLoggedInAsVendor ? Html.Raw("style='display: none;'") : null)>
                                <div class="col-md-4">
                                    <nop-label asp-for="SearchVendorId" />
                                </div>
                                <div class="col-md-8">
                                    <nop-select asp-for="SearchVendorId" asp-items="Model.AvailableVendors" />
                                </div>
                            </div>
                        </div>
                        <div class="col-md-7">
                            <div class="form-group">
                                <div class="col-md-3">
                                    <nop-label asp-for="StartDate" />
                                </div>
                                <div class="col-md-9">
                                    <nop-editor asp-for="StartDate" />
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-md-3">
                                    <nop-label asp-for="EndDate" />
                                </div>
                                <div class="col-md-9">
                                    <nop-editor asp-for="EndDate" />
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-7 col-md-offset-5">
                                <button type="button" id="search-neversoldreport" class="btn btn-primary btn-search">
                                    <i class="fa fa-line-chart"></i>
                                    @T("Admin.SalesReport.NeverSold.RunReport")
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="panel panel-default">
                <div class="panel-body">
                    <div id="neversoldreport-grid"></div>

                    <script type="text/javascript">
                        $(document).ready(function () {
                            $("#neversoldreport-grid").kendoGrid({
                                dataSource: {
                                    type: "json",
                                    transport: {
                                        read: {
                                            url: "@Html.Raw(Url.Action("NeverSoldReportList", "Order"))",
                                            type: "POST",
                                            dataType: "json",
                                            data: additionalData
                                        }
                                    },
                                    schema: {
                                        data: "Data",
                                        total: "Total",
                                        errors: "Errors"
                                    },
                                    error: function(e) {
                                        display_kendoui_grid_error(e);
                                        // Cancel the changes
                                        this.cancelChanges();
                                    },
                                    pageSize: @(defaultGridPageSize),
                                    serverPaging: true,
                                    serverFiltering: true,
                                    serverSorting: true
                                },
                                pageable: {
                                    refresh: true,
                                    pageSizes: [@(gridPageSizes)],
                                    @await Html.PartialAsync("_GridPagerMessages")
                                },
                                editable: {
                                    confirmation: "@T("Admin.Common.DeleteConfirmation")",
                                    mode: "inline"
                                },
                                scrollable: false,
                                columns: [{
                                    field: "ProductName",
                                    title: "@T("Admin.SalesReport.NeverSold.Fields.Name")"
                                }, {
                                    field: "ProductId",
                                    title: "@T("Admin.Common.View")",
                                    width: 100,
                                    headerAttributes: { style: "text-align:center" },
                                    attributes: { style: "text-align:center" },
                                    template: '<a class="btn btn-default" href="@Url.Content("~/Admin/Product/Edit/")#=ProductId#"><i class="fa fa-eye"></i>@T("Admin.Common.View")</a>'
                                }]
                            });
                        });
                    </script>

                    <script type="text/javascript">
                        $(document).ready(function () {
                            $('#search-neversoldreport').click(function () {
                                var grid = $('#neversoldreport-grid').data('kendoGrid');
                                grid.dataSource.page(1); //new search. Set page size to 1
                                //grid.dataSource.read(); we already loaded the grid above using "page" function
                                return false;
                            });
                        });

                        function additionalData() {
                            var data = {
                                StartDate: $('#@Html.IdFor(model => model.StartDate)').val(),
                                EndDate: $('#@Html.IdFor(model => model.EndDate)').val(),
                                SearchCategoryId: $('#SearchCategoryId').val(),
                                SearchManufacturerId: $('#SearchManufacturerId').val(),
                                SearchStoreId: $('#SearchStoreId').val(),
                                SearchVendorId: $('#SearchVendorId').val()
                            };
                            addAntiForgeryToken(data);
                            return data;
                        }
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>